package com.teradata.olingo.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;

import java.util.concurrent.Future;

/**
 * @Project: cmcchq
 * @Description:
 * @Version 1.0
 * @Throws :
 * @Author: <li>2019/5/7 lyndon Create 1.0
 * @Copyright (c)2019-2019 版权所有
 * @Modified By:
 */
@Slf4j
@Service
public class TestService {

    @Async("threadPoolTaskExecutor")
    public Future<String> call() {
        try{
            System.out.println("test service thread name:" + Thread.currentThread().getName());
            Thread.sleep(10000);
            String response = "success";
            //some business logic here
            log.info("call success");
            System.out.println("call success");
            return new AsyncResult<>(response);
        } catch (Exception e) {
            //some cancel/rollback logic when the request is cancelled
            return null;
        }
    }
}